package com.hotacorp.opencloud.authserver.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.ClientRegistrationException;
import org.springframework.security.oauth2.provider.NoSuchClientException;
import org.springframework.stereotype.Component;

import com.hotacorp.opencloud.authserver.bean.SysCientDetail;
import com.hotacorp.opencloud.authserver.feign.UserFeignClient;
import com.hotacorp.opencloud.common.authcommon.SysClientBean;
import com.hotacorp.opencloud.common.commdata.Result;

/**
 * ClientDetailsService实现类
 * @author lwg
 *
 */
@Component
public class ClientDetailsServiceImpl implements ClientDetailsService {
	@Autowired
	private UserFeignClient userFeignClient;

	@Override
	public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
		Result<SysClientBean> result = userFeignClient.loadClientByClientId(clientId);
		if (result.getCode() == 0) {
			return new SysCientDetail(result.getData());
		} else {
			throw new NoSuchClientException(result.getMsg());
		}
	}

}
